<template>
	<view class="">
		<view class="header">
			<span style="padding-bottom: 20rpx;"><u-icon label="注意事项" labelColor="black" size="50" labelSize="40"
					name="volume"></u-icon></span>
					<span>{{sss}}</span>
			<span v-html="htmls"></span>
		</view>
		<view class="lis"></view>
		<view class="conter">
			<span style="color: black;font-size: 38rpx;font-weight: bold;">{{items.Name}}</span>
			<span>联系电话：&nbsp;{{items.Mobile}}</span>
			<span>患者身份证：&nbsp;{{items.IDCard}}</span>
		</view>
		<view class="lis"></view>
		<view class="bottomtext">
			<span style="font-size: 36rpx; color: black;"><span class="tiao">|</span> 预约信息</span>
			<span>就诊科室：{{doctlist.DepartmentName}}</span>
			<span>医生姓名：{{doctlist.DoctorName}}</span>
			<span>就诊时段：{{doctor.day}} {{doctor.week}} {{doctor.times}}</span>
			<!-- <span>号段：{{doctor.remain}}</span> -->
			<span style="font-size: 45rpx;">金额：<span style="color: red;">{{doctor.money}} ￥</span></span>
			<!-- <span>就诊地点：</span> -->
			<span>病情主诉：</span>
			<!-- <u--textarea v-model="Disease" count placeholder="请输入病情主诉" maxlength="200"></u--textarea> -->
			<u-input v-model="Disease" type="textarea" border="true" placeholder="请输入病情主诉" maxlength="500" />
		</view>
		<view class="lis"></view>
		<u-toast ref="uToast"></u-toast>
		<view class="subil">
			<view class="buttons">
				<u-button type="primary" @click="confirm(doctor.money)">确认预约</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				sss:'',
				htmls: '',
				items: [],
				doctor: [],
				Disease: '',
				show: false,
				merry: {
					type: 'error',
					icon: false,
					message: "已约满",
					iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/error.png'

				},
				doctlist: []
			}
		},
		onLoad: function(list) {
			this.getconfims(list)
			this.getMpWxCode()
			this.aaa()
		},
		computed: {},
		methods: {
			aaa() {

				this.$request("help", "Detail", {
					code: 'zhuyishixiang'
				}).then(res => {
					console.log("住院收费", res)
					if (res.code == 1) {
						this.htmls = res.data.content
						// uni.hideLoading();

					} else {
						// uni.hideLoading();
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				}).catch(err => {
					// uni.hideLoading();
					console.log("err", err)
					uni.showToast({
						title: err,
						icon: 'none',
						duration: 1000
					});

				});
			},
			async getconfims(list) {
				// console.log(list)
				this.items = JSON.parse(list.items)
				this.doctor = JSON.parse(list.doctorinfor)
				// console.log("doctor",this.doctor)
				this.doctlist = JSON.parse(list.doctlist)
				// console.log(JSON.parse(item))
			},
			getMpWxCode() {
				console.log("进了")
				uni.login({
					success: async resCode => {
						console.log("rescode", resCode)
						let res = await this.$request('auth', 'getopenid', {
							Code: resCode.code
						});
						console.log("获取openid", res)
						if (res.code === 1) {
							console.log("res", res)
							this.appid = res.data.appid;
							this.sessionkey = res.data.session_key;
							this.openid = res.data.openid;
						}
					}
				})
			},
			gzhjweixin() { //微信支付
				//复兴眼科
				//京城
				var appid = 'wxa642be82ca0d3c30';
				return
				
			},
			confirm(e) {
				// let money = parseInt(e)
				let then=this
				
				this.$request("Order", "Submit", {
					PatientId: this.items.PatientId,
					TimeSpaceId: this.doctor.timeId,
					Memo: this.Disease
				}).then(res => {
					console.log("提交订单res", res)
					if(res.code!=1){
						uni.showToast({
							title: res.msg,
							icon: "none",
							duration: 2000,
						});
						return
					}
					if (res.data.PayStatus == 1) {
						this.$request("pay","pay",{
								OrderNo:res.data.OrderNo,
							}).then(resa=>{
								console.log("订单号",res)
								WeixinJSBridge.invoke('getBrandWCPayRequest', {
										"appId": resa.data.appId, //公众号ID，由商户传入     
										"timeStamp": resa.data.timeStamp, //时间戳，自1970年以来的秒数     
										"nonceStr": resa.data.nonceStr, //随机串     
										"package": resa.data.package,
										"signType": resa.data.signType, //微信签名方式：     
										"paySign": resa.data.paySign //微信签名 
									},
									function(res) {
										// then.sss=res
										// console.log("支付",res)
										if (res.err_msg == "get_brand_wcpay_request:ok") {
											uni.showToast({
												title: "成功支付",
												icon: "none",
												duration: 2000,
											});
											setTimeout(function() {
												uni.reLaunch({
													url: `/pages/register/Scheduling/record/record?current=${3}`,
													// url: '/pages/zhuyaun/xxoo/xxoo',
													fail(error) {
														console.log(error)
													}
												})
											}, 2000);
											
										}else{
											uni.showToast({
												title: "支付未成功",
												icon: "none",
												duration: 2000,
											});
											setTimeout(function() {
												uni.reLaunch({
													url: `/pages/register/Scheduling/record/record?current=${2}`,
													// url: '/pages/zhuyaun/xxoo/xxoo',
													fail(error) {
														console.log(error)
													}
												})
											}, 2000);
										}
									});
							})
						
					} else {
						uni.reLaunch({
							url: `/pages/register/Scheduling/record/record`,
							// url: '/pages/zhuyaun/xxoo/xxoo',
							fail(error) {
								console.log(error)
							}
						})
						return
					}
				})


			},
			showToast(params) {
				this.$refs.uToast.show({
					...params,
					complete() {
						params.url && uni.navigateTo({
							url: params.url
						})
					}
				})
			}
		}
	}
</script>

<style>
	@import './confirm.css'
</style>